package display;
import java.util.*;
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
import org.springframework.web.context.*;

import domain.TrackRepository;
import domain.CDRepository;
import domain.Track;
import domain.CD;

import util.TrackDTO;
import util.CDDTO;
import util.TrackAssembler;
import util.CDAssembler;

/**
* Clase controladora del detalle de Tracks.
* @version 1, 5/10/2014
* @author Diego Cordero, Bryan Morales.
*/
public class InsertarTrack extends PageController {
  

  /** 
	 * obtiene los parametros del formulario de Tracks para ser consultados. 	 	 	 
	 * @version 1, 5/10/2014
	 * @author Diego Cordero, Bryan Morales.	 
	 * @return void
	 */
  public void doGet(HttpServletRequest request,HttpServletResponse response)
    throws ServletException, IOException {

	  CDRepository objs = (CDRepository) context.getBean("CDRepository");
    try {
			Collection lista = objs.findAll();
			List data = new ArrayList();
			Iterator itr = lista.iterator();
			while (itr.hasNext()) {
				CD obj = (CD)itr.next();
				CDDTO dto = CDAssembler.createDTO(obj);				
				data.add(dto);				
			}
			
		  request.setAttribute("CDs",data);		 
		  forward("/agregarTrack.jsp",request,response);
		} catch (Exception e) {
			request.setAttribute("mensaje",e.getMessage());
			forward("/paginaError.jsp",request,response);
		}
  }
}